package com.atguigu.exam.exception;

import com.atguigu.exam.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author 韩总
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    //处理异常的方法
    @ExceptionHandler(value = Exception.class)
    public Result doResolveException(Exception e){
        log.error("系统异常：{}", e.getMessage());
        return Result.error(e.getMessage());
    }

    //处理EaxamException异常的方法
    @ExceptionHandler(value = ExamException.class)
    public Result doResolveException(ExamException e){
        log.error("业务异常：{}", e.getMessage());
        return Result.error(e.getCode(), e.getMessage());
    }
}
